< previous page page_977 next page >

Page 977
e7ae6bd512ad4c3583017fcda52f57ae.gif
· Physical media errors: Errors that are caused by physical devices, such as printers and disk drives.
e7ae6bd512ad4c3583017fcda52f57ae.gif
· Program code errors: Errors that result from improper coding.
8. You should not use error trapping for the Visual Basic Data Control because it provides its own error trapping.
9. It is a good idea to open a data table with the FORM LOAD event. This allows you to capture most database-related errors prior to any data entry.
10. The advantage of a global error handler is that it enables you to create a single module that handles all expected errors. The major disadvantage of a global error handler is that you are not able to resume processing at the point at which the error occurs. To be able to resume processing at the point of an error, you need to use Resume, Resume Next, or Resume label in a local error handler.
11. The Err.Raise method allows you to create your own error message and confirm to the Visual Basic standard, including the ability to "post" a message to another application through the OLE object model interface.
Answers to Day 14 Exercises
1. Insert a command button on a new form, and then double-click that button and enter the following code:
Private Sub Command1_Click()
    On Error GoTo Command1Clickerr
    Dim cMsg As String ' Declare string
    Open "C:\ABC.TXT" For Input As 1 'Open file
    GoTo Command1ClickExit
'Error handler
Command1Clickerr:
    If Err.Number = 53 Then
        cMsg = "Unable to open ABC.TXT" + Chr(13)
        MsgBox cMsg, vbCritical, "Command1Click"
        Unload Me
        End
    Else
        MsgBox CStr(Err.Number) & " - " & Err.Description, vbCritical,
"Command1Click"
        Resume Next
    End If
'Routine exit
Command1ClickExit:
End Sub
2. You first need to place a common dialog on your form. Then place a command button and add the following code to it:
Private Sub Command2_Click()
    On Error GoTo Command2ClickErr
    'Declare variables

 
< previous page page_977 next page >

If you like this book, buy it!